package practice;

import java.util.Scanner;

//  因为每次输入都不同，所以最后一次输入面积一定最大！！！
public class _14Paint {
    static int n,m,k;
    static int[][] xy;
    final static int C = 5010;
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        k = scanner.nextInt();

        int x, y, c = 0;
        for (int i = 0; i < k; i++) {
            x = scanner.nextInt();
            y = scanner.nextInt();
            c = scanner.nextInt();
        }
        System.out.println(n+m-1 + " " + c);
    }
}
